package BasicClass.One;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class BasicOne11 {
    public static void main(String[] args) throws IOException {
        BasicOne11 main = new BasicOne11();
        main.Main();
    }

    /**
     * 定义局部最小的概念。arr长度为1时，arr[0]是局部最小。arr的长度为N(N>1)时，如果arr[0] < arr[1]，那么arr[0]是局部最小；
     * 如果arr[N-1]<arr[N-2],那么arr[N-1]是局部最小；如果0<i<N-1，既有arr[i] < arr[i-1]，又有arr[i] < arr[i + 1]，那么arr[i]
     * 是局部最小。给定无序数组arr,已知arr中任意两个相邻的数都不相等，只需要返回arr中任意一个局部最小出现的位置即可，如果不存在这个位置就输出-1。
     */
    public void Main() throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        int size = Integer.parseInt(reader.readLine());
        String[] nums = reader.readLine().split(" ");
        int[] ints = new int[size];
        for (int i = 0; i < size; i++) {
            ints[i]=Integer.parseInt(nums[i]);
        }
        int index = -1;
        if(size==1){
            System.out.println(index);
            return;
        }else if(size==2){
            index = Math.min(ints[0],ints[1]);
            System.out.println(index);
            return;
        }
        if(ints[0]<ints[1]){
            System.out.println(0);
            return;
        }
        if(ints[size-1]<ints[size-2]){
            System.out.println(size-1);
            return;
        }

        int left = 0;
        int right = size-1;
        while (left<right){
            int mid = ((right-left)>>1)+left;
            if(ints[mid]<ints[mid-1]){
                if(ints[mid]<ints[mid+1]){
                    System.out.println(mid);
                    return;
                }
                left = mid;
            }else{
                right = mid;
            }
        }
        System.out.println(index);
    }
}
